
package com.rx.mgt.controller;  

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.rx.mgt.domain.AdminUser;
import com.rx.mgt.domain.SysParam;
import com.rx.mgt.po.MailBaseBo;
import com.rx.mgt.po.UsersBo;
import com.rx.mgt.service.DomainService;
import com.rx.mgt.service.SysLogService;
import com.rx.mgt.service.SysParamService;
import com.rx.mgt.util.IpUtil;

/** 
 * ClassName:SysParamVController 
 * Function :
 * Reason   : 
 * Date     :Jan 31, 2017 9:35:10 PM 
 * @author   luolei 
 * @since    JDK 1.6
 */
@Controller
public class SysParamVController {
    @Autowired
    SysParamService sysParamService;
    @Autowired
    DomainService domainService;
    @Autowired
    SysLogService sysLogService;
    
    @RequestMapping(value="/sys-mail-base.htmlx")
    public String  sysMailBase(ModelMap model,HttpServletRequest request,UsersBo usersBo){
        AdminUser user = (AdminUser) request.getSession().getAttribute("user");
        if("2".equals(user.getType())){
            usersBo.setDomain(user.getDomain());
        }
        List list = domainService.getDomainInfoExt(usersBo);
        model.addAttribute("domainList",list);
        SysParam s1 = sysParamService.getSysParamByKey("base", "base.domain");
        SysParam s2 =sysParamService.getSysParamByKey("base", "base.logo");
        SysParam s3 =sysParamService.getSysParamByKey("base", "base.template");
        SysParam s4 =sysParamService.getSysParamByKey("base", "base.sign");
        SysParam s5 =sysParamService.getSysParamByKey("server", "server.jdk");
        SysParam s6 =sysParamService.getSysParamByKey("server", "server.run");
        SysParam s7 =sysParamService.getSysParamByKey("server", "server.other");//其他启动参数
        SysParam s9 = sysParamService.getSysParamByKey("system", "system.announcement");//系统公告
        SysParam s8 =sysParamService.getSysParamByKey("server", "server.relay.forwarding");//中继转发地址
        model.addAttribute("domain",s1);
        model.addAttribute("logo",s2);
        model.addAttribute("template",s3);
        model.addAttribute("sign",s4);
        model.addAttribute("jdk",s5);
        model.addAttribute("run",s6);
        model.addAttribute("other",s7);
        model.addAttribute("forwarding",s8);
        model.addAttribute("announcement",s9);
        return "sys-mail-base";
    } 
    @ResponseBody
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @RequestMapping(value="/article_save_submit1.htmlx")
    public Map  articleSaveSubmit1(HttpServletRequest request ,ModelMap model,MailBaseBo mailBaseBo){
        AdminUser user = (AdminUser) request.getSession().getAttribute("user");
        sysLogService.add("更新邮件基本设置", IpUtil.getIpAddr(request), "管理", user.getId()+"", user.getUser_name());
        Map map =new HashMap();
        map.put("result", "success");
        return map;
    }
    @ResponseBody
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @RequestMapping(value="/article_save_submit2.htmlx")
    public Map  articleSaveSubmit2(HttpServletRequest request ,ModelMap model,MailBaseBo mailBaseBo){
        AdminUser user = (AdminUser) request.getSession().getAttribute("user");
        sysLogService.add("更新邮件引擎", IpUtil.getIpAddr(request), "管理", user.getId()+"", user.getUser_name());
        Map map =new HashMap();
        map.put("result", "success");
        SysParam s5 =sysParamService.getSysParamByKey("server", "server.jdk");
        SysParam s6 =sysParamService.getSysParamByKey("server", "server.run");
        SysParam s7 =sysParamService.getSysParamByKey("server", "server.other");//其他启动参数
        s5.setParamValue(mailBaseBo.getJdk());
        s6.setParamValue(mailBaseBo.getRun());
        s7.setParamValue(mailBaseBo.getOther());
        sysParamService.update(s5);
        sysParamService.update(s6);
        sysParamService.update(s7);
        return map;
    }
    @ResponseBody
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @RequestMapping(value="/article_save_submit3.htmlx")
    public Map  articleSaveSubmit3(HttpServletRequest request ,ModelMap model,MailBaseBo mailBaseBo){
        AdminUser user = (AdminUser) request.getSession().getAttribute("user");
        sysLogService.add("更新系统公告", IpUtil.getIpAddr(request), "管理", user.getId()+"", user.getUser_name());
        Map map =new HashMap();
        map.put("result", "success");
        SysParam sysParam = sysParamService.getSysParamByKey("system", "system.announcement");//系统公告
        if(sysParam!=null){
            sysParam.setParamValue(mailBaseBo.getAnnouncement());
            sysParamService.update(sysParam);
        }
        return map;
    }
    @ResponseBody
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @RequestMapping(value="/article_save_submit4.htmlx")
    public Map  articleSaveSubmit4(HttpServletRequest request ,ModelMap model,MailBaseBo mailBaseBo){
        AdminUser user = (AdminUser) request.getSession().getAttribute("user");
        sysLogService.add("更新中继设置", IpUtil.getIpAddr(request), "管理", user.getId()+"", user.getUser_name());
        Map map =new HashMap();
        map.put("result", "success");
        SysParam s8 =sysParamService.getSysParamByKey("server", "server.relay.forwarding");//中继转发地址
        s8.setParamValue(mailBaseBo.getForwarding());
        sysParamService.update(s8);
        return map;
    }
}
  